package ${packageName}.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import ${packageName}.entity.${upperDataKey};
import ${packageName}.mapper.${upperDataKey}Mapper;
import ${packageName}.pojo.dto.${upperDataKey}AddRequest;
import ${packageName}.pojo.dto.${upperDataKey}EditRequest;
import ${packageName}.pojo.dto.${upperDataKey}QueryRequest;
import ${packageName}.pojo.vo.${upperDataKey}VO;
import ${packageName}.service.${upperDataKey}Service;

/**
 * ${dataName}服务实现
 *
 */
@Service
@Slf4j
public class ${upperDataKey}ServiceImpl extends ServiceImpl<${upperDataKey}Mapper, ${upperDataKey}> implements ${upperDataKey}Service {

    // region 增删改查
    /**
    * 新增${dataName}
    * @param ${dataKey}AddRequest
    */
    @Override
    public void add(${upperDataKey}AddRequest ${dataKey}AddRequest){
        ${upperDataKey} ${dataKey} = new ${upperDataKey}();
        BeanUtils.copyProperties(${dataKey}AddRequest, ${dataKey});
        this.save(${dataKey});
    }

    /**
    * 编辑${dataName}
    * @param ${dataKey}EditRequest
    */
    public void edit(${upperDataKey}EditRequest ${dataKey}EditRequest){
        ${upperDataKey} ${dataKey} = new ${upperDataKey}();
        BeanUtils.copyProperties(${dataKey}EditRequest, ${dataKey});
        this.updateById(${dataKey});
    }

    /**
    * 分页获取${dataName}列表
    * @param ${dataKey}QueryRequest
    */
    public IPage<${upperDataKey}VO> selPage(${upperDataKey}QueryRequest ${dataKey}QueryRequest){
        return this.baseMapper.selectPage(${dataKey}QueryRequest.toPage(), Wrappers.<${upperDataKey}>lambdaQuery()).convert(item -> {
        ${upperDataKey}VO vo = new ${upperDataKey}VO();
        BeanUtils.copyProperties(item, vo);
        return vo;
        });
    }

    /**
    * 删除${dataName}
    * @param id
    */
    public void delById(String id){
        this.removeById(id);
    }
    // endregion
}
